package com.zhima.controller.feign;

import com.zhima.service.impl.EmailCheckCodeServiceImpl;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feign/email")
public class EmailFeignController {
    @Autowired
    private EmailCheckCodeServiceImpl emailCheckCodeService;

    /**
     * 验证邮箱验证码
     *
     * @param toEmail
     * @param submitCheckCode
     * @return
     */
    @GetMapping("/verify/{submitCheckCode}/{toEmail}")
    public String verifyEmailCheckCode(@PathVariable("toEmail") String toEmail, @PathVariable("submitCheckCode") String submitCheckCode) {
        return emailCheckCodeService.verifyCheckCode(toEmail, submitCheckCode);
    }

    /**
     * 验证邮箱验证码
     *
     * @param submitCheckCode
     * @return
     */
    @GetMapping("/verify/{submitCheckCode}")
    public String verifyEmailCheckCode(@PathVariable("submitCheckCode") String submitCheckCode) {
        return emailCheckCodeService.verifyCheckCode(UserHolder.get().getEmail(), submitCheckCode);
    }
}
